class UsersController < ApplicationController
    include AuthenticatedSystem
    before_filter :login_from_cookie
  def index
     @user = User.paginate :page => params[:page], :per_page => 10
  end

  def show

  end

  def new
    @user = User.new
  end

  def edit
    @user = User.find(params[:id])
  end

  def create
    @user = User.new(params[:user])
    return unless request.post?
    if @user.save
      flash[:notice] = 'Usuário cadastrado com sucesso.'
      redirect_to :action => "index"
    else
      render :action => "new"
    end
  end


  # PUT /users/1
  def update
    puts "sss"
    @user = User.find(params[:id])
      if @user.update_attributes(params[:user])
        flash[:notice] = 'Usuário editado com sucesso.'
        puts "emcima"
        redirect_to :action => 'index'
      else
        puts "aqui"
        render :action => "edit"
      end     
  end

  def destroy
    @user = User.find(params[:id])
    @user.destroy

    respond_to do |format|
      format.html { redirect_to(users_url) }
      format.xml  { head :ok }
    end
  end
end
